package org.bluedream.core.module.controller.goods;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.goods.BrandItem;
import org.bluedream.core.module.service.goods.BrandItemService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @ClassName BrandItemController
 * @Description TODO
 * @Author foxsand
 * @Data 2021-07-29 15:39
 * @Version
 */
@Controller
@RequestMapping(value = "${adminPath}/brandItem")
public class BrandItemController extends BaseController {
    @Resource
    private BrandItemService brandItemService;

    @ModelAttribute
    public BrandItem get(String id){
        return brandItemService.getById(id);
    }

    @RequiresPermissions("brandItem:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(BrandItem entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("brandItem" , entity);
        return "module/brandItem/brandItemList";
    }

    @RequiresPermissions("brandItem:view")
    @RequestMapping("/form")
    public String form(BrandItem entity, Model model){
        model.addAttribute("brandItem" , entity);
        return "module/brandItem/brandItemForm";
    }

    @RequiresPermissions("brandItem:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<BrandItem> findPage(@RsaSecurityParameter BrandItem entity){
        return brandItemService.findPage(entity);
    }

    @RequiresPermissions("brandItem:edit")
    @RequestMapping("/save")
    @ResponseBody
    public String save(BrandItem entity){
        boolean flag = brandItemService.save(entity);
        if (flag){
            return "品牌信息保存成功";
        }else {
            return "品牌信息保存失败";
        }
    }
}
